#!/usr/bin/python
# encoding: utf-8

import time
from pykafka import KafkaClient


client = KafkaClient(
    hosts="192.168.101.2:9093,192.168.101.2:9094,192.168.101.2:9095")  # 可接受多个Client这是重点
# client.topics  # 查看所有topic
topic = client.topics[b'my.test'] # 选择一个topic

producer = topic.get_producer()

for i in range(100):
    msg = 'test message {}'.format(i)
    producer.produce(msg.encode('utf-8'))
    print(msg)
    time.sleep(1)
    
